<?php
namespace app\mall\home;

use app\common\controller\BaseController;
use app\mall\model\Qrcode as QrcodeModel;
use qrcode\Qrcode as QrcodeTool;

class Source extends BaseController
{
	/**
	 * 二维码生成
	 * @package app\merch\home
	 */
    public function code($id = 0)
    {
		if ($id === 0) $this->error('参数错误');
		$file = public_path().'/uploads/qrcode/'.$id.'.png';
		if (is_file($file)) {
			return redirect('/uploads/qrcode/'.$id.'.png');
		} else {
			$qrcode = new QrcodeTool;
			$url = real_url('mall/source/query', ['id' => $id]);
			$qrcode->make($url, 14);
		}
    }
	/**
	 * 溯源码控制器
	 * @package app\merch\home
	 */
	public function query($id = 0)
	{
		$this->assign('id', $id);
		// 获取所有导航
		$nav = \app\cms\model\Nav::getNav();
		$this->assign('nav', $nav);
		return $this->fetch();
		if ($id === 0) $this->error('参数错误');
		$file = public_path().'/uploads/qrcode/'.$id.'.png';
		if (is_file($file)) {
			return redirect('/uploads/qrcode/'.$id.'.png');
		} else {
			$qrcode = new QrcodeTool;
			$url = real_url('mall/source/query', ['id' => $id]);
			$qrcode->make($url, 14);
		}
	}
}
